package com.chijun.mform.create.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import com.chijun.mform.R;
import com.example.ccj.b.c.custom.tree.ISelectTreeListener;
import com.example.ccj.b.c.custom.tree.TreeMode;
import com.example.ccj.b.c.custom.tree.TreeView;
import com.example.ccj.b.c.dialog.DialogBase;
import com.example.ccj.u.StringUtils;

import java.util.List;

/**
 * 选择人员dialog
 * 点击后返回
 */
public class SelectPersonDialog extends DialogBase {

    String treeViewName;
    ISelectTreeListener iSelectTreeListener;


    /**
     *
     * @param context 上下文
     * @param treeViewName 抬头名称
     * @param iSelectTreeListener 选择后的回调
     */
    public SelectPersonDialog(@NonNull Context context,
                              String treeViewName,
                              ISelectTreeListener iSelectTreeListener) {
        super(context);
        this.treeViewName = treeViewName;
        this.iSelectTreeListener = iSelectTreeListener;
    }


    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_select_person);
        setAlpha(1f);//透明度
        isCanClose(false);//点击不允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.7);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);//是否铺满
        goneTitleLeftImage();


        if (StringUtils.isEmpty(treeViewName)) treeViewName = "请选择审批人员";
        setTitleCenterText(treeViewName);
        setTitleRightText("OK").setOnClickListener(V->{
            dismiss();
        });
    }

    public void setTreeModeList(List<TreeMode> treeModeList ){
        ProgressBar progressBar = findViewById(R.id.dialog_select_person_progress);
        TreeView treeView = findViewById(R.id.dialog_select_person_tree);
        treeView.setTitleName(treeViewName)
                .setShowLevel(2) // 显示级别
                .setOnlyShowMuLu(false) //初始加载是否只显示目录
                .setSuoJinJiBie(3)//缩进级别
                .setDataDefaultImageResource(com.example.ccj.R.mipmap.bar_code)//数据默认图标
                .setMuLuDefaultImageResource(com.example.ccj.R.mipmap.drawing_boar_brush_gray)//目录默认图标
                .setData(treeModeList)//数据
                .setSelectTreeListener(iSelectTreeListener)
                //选中或取消选中回调
                .show();//绘制
        progressBar.setVisibility(View.GONE);
    }

}
